package com.item.service.impl;

import com.github.pagehelper.PageHelper;
import com.item.domain.TbUserVisitor;
import com.item.mapper.TbUserVisitorMapper;
import com.item.po.TbUserVisitorPo;
import com.item.service.TbUserVisitorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbUserVisitorServiceImpl implements TbUserVisitorsService {

    @Autowired
    TbUserVisitorMapper tbUserVisitorMapper;


    public List<TbUserVisitorPo> findAll(int limit, int page, TbUserVisitor tbUserVisitor) {
        if (limit > 0 && page > 0) {
            PageHelper.startPage(limit, page);
        }
        return tbUserVisitorMapper.findAll(tbUserVisitor);
    }


    public int add(TbUserVisitor tbUserVisitor) {

        TbUserVisitor tbUserVisitor1 = tbUserVisitorMapper.selectFindUser(tbUserVisitor);
        if (tbUserVisitor1 != null) {
            tbUserVisitor.setCreateTime(System.currentTimeMillis() + "");
            return tbUserVisitorMapper.updateByPrimaryKeySelective(tbUserVisitor);
        } else {
            tbUserVisitor.setCreateTime(System.currentTimeMillis() + "");
            return tbUserVisitorMapper.insertSelective(tbUserVisitor);
        }


    }


    public int update(TbUserVisitor tbUserVisitor) {
        return tbUserVisitorMapper.updateByPrimaryKey(tbUserVisitor);
    }

    @Override
    public int delete(int id) {
        return tbUserVisitorMapper.deleteByPrimaryKey(id);
    }
}
